package change

import (
	"jlpay-sdk-go/pkg/jlpay/models"
)

// SettleRuleModifyRequest 商户结算规则修改请求
type SettleRuleModifyRequest struct {
	*models.OrgBaseRequest
	ApplyID           string `json:"apply_id"`            // 申请单id
	SettleMode        string `json:"settle_mode"`         // 结算方式
	DayCut            string `json:"day_cut"`             // 营业周期，结算日切时间
	SettleSession     string `json:"settle_session"`      // 结算场次
	AccountChangeFlag string `json:"account_change_flag"` // 是否允许商户自主变更结算账户，0-否1-是
	Postscript        string `json:"postscript"`          // 结算附言
}

// NewSettleRuleModifyRequest 创建结算规则修改请求实例
func NewSettleRuleModifyRequest() *SettleRuleModifyRequest {
	return &SettleRuleModifyRequest{
		OrgBaseRequest: &models.OrgBaseRequest{},
	}
}

// SetApplyID 设置申请单id
func (r *SettleRuleModifyRequest) SetApplyID(applyID string) *SettleRuleModifyRequest {
	r.ApplyID = applyID
	return r
}

// SetSettleMode 设置结算方式
func (r *SettleRuleModifyRequest) SetSettleMode(settleMode string) *SettleRuleModifyRequest {
	r.SettleMode = settleMode
	return r
}

// SetDayCut 设置营业周期，结算日切时间
func (r *SettleRuleModifyRequest) SetDayCut(dayCut string) *SettleRuleModifyRequest {
	r.DayCut = dayCut
	return r
}

// SetSettleSession 设置结算场次
func (r *SettleRuleModifyRequest) SetSettleSession(settleSession string) *SettleRuleModifyRequest {
	r.SettleSession = settleSession
	return r
}

// SetAccountChangeFlag 设置是否允许商户自主变更结算账户
func (r *SettleRuleModifyRequest) SetAccountChangeFlag(accountChangeFlag string) *SettleRuleModifyRequest {
	r.AccountChangeFlag = accountChangeFlag
	return r
}

// SetPostscript 设置结算附言
func (r *SettleRuleModifyRequest) SetPostscript(postscript string) *SettleRuleModifyRequest {
	r.Postscript = postscript
	return r
}

// ToMap 将请求对象转换为字典
func (r *SettleRuleModifyRequest) ToMap() (map[string]interface{}, error) {
	data, err := r.OrgBaseRequest.ToMap()
	if err != nil {
		return nil, err
	}

	data["apply_id"] = r.ApplyID
	data["settle_mode"] = r.SettleMode
	data["day_cut"] = r.DayCut
	data["settle_session"] = r.SettleSession
	data["account_change_flag"] = r.AccountChangeFlag
	data["postscript"] = r.Postscript

	return data, nil
}

// SettleRuleModifyResponse 商户结算规则修改响应参数
type SettleRuleModifyResponse struct {
	*models.StandardResponse
	MerchNo string `json:"merch_no"` // 商户号
	ApplyID string `json:"apply_id"` // 业务申请编号
}

// NewSettleRuleModifyResponse 创建结算规则修改响应实例
func NewSettleRuleModifyResponse() *SettleRuleModifyResponse {
	return &SettleRuleModifyResponse{
		StandardResponse: &models.StandardResponse{},
	}
}

// ToMap 将响应对象转换为字典
func (r *SettleRuleModifyResponse) ToMap() (map[string]interface{}, error) {
	data := make(map[string]interface{})

	// 添加基础响应字段
	if r.RetCode != "" {
		data["ret_code"] = r.RetCode
	}
	if r.RetMsg != "" {
		data["ret_msg"] = r.RetMsg
	}

	// 添加业务字段
	if r.MerchNo != "" {
		data["merch_no"] = r.MerchNo
	}
	if r.ApplyID != "" {
		data["apply_id"] = r.ApplyID
	}

	return data, nil
}
